package com.jx.driving.request.domain;

import java.nio.ByteBuffer;
import java.util.Arrays;

import com.jx.driving.protocol.terminal.annotation.ByteAnnotation;
import com.jx.driving.protocol.terminal.annotation.DynamicByteArrayAnnotation;
import com.jx.driving.protocol.terminal.annotation.TerminalAnnotation;
import com.jx.driving.util.ByteUtils;

/**
 * 附加信息
 * 
 * @author shenliuyang
 *
 *         2016年8月14日下午2:41:44
 */
@TerminalAnnotation
public class LocationAttachement {
	@ByteAnnotation(order = 1)
	private short id;// 附加信息id
	@DynamicByteArrayAnnotation(value = 1, order = 2)
	private byte[] data;// 附加信息内容

	public short getId() {
		return id;
	}

	public void setId(short id) {
		this.id = id;
	}

	public long getLong() {
		return ByteUtils.byteToLong(data);
	}

	public void setLong(long value) {
		data = new byte[4];
		ByteBuffer bf = ByteBuffer.wrap(data);
		bf.putInt((int) value);
	}

	public int getInt() {
		return ByteUtils.bytes2int(data);
	}

	public void setInt(int value) {
		data = new byte[2];
		ByteBuffer bf = ByteBuffer.wrap(data);
		bf.putShort((short) value);
	}

	public byte[] getContent() {
		return data;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("LocationAttachement [id=").append(id).append(", data=").append(Arrays.toString(data))
				.append("]");
		return builder.toString();
	}

}
